package com.org.khtn.gui;

import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;


public class TreeRender extends DefaultTreeCellRenderer {

    Icon serverIcon;
    Icon databaseIcon;
    Icon databasesIcon;
    Icon tableIcon;
    Icon tablesIcon;

    public TreeRender(Icon server, Icon database, Icon databases, Icon tables, Icon table) {
        serverIcon = server;
        databaseIcon = database;
        databasesIcon = databases;
        tableIcon = table;
        tablesIcon = tables;
    }

    public Component getTreeCellRendererComponent(
            JTree tree,
            Object value,
            boolean sel,
            boolean expanded,
            boolean leaf,
            int row,
            boolean hasFocus) {

        super.getTreeCellRendererComponent(
                tree, value, sel,
                expanded, leaf, row,
                hasFocus);
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        if (node.isRoot()) {
            setIcon(serverIcon);
        } else if ((node.toString().compareTo("Databases") == 0)
                && (node.getParent().toString().compareTo("Server") == 0)
                && (node.getLevel() == 1)) {
            setIcon(databasesIcon);
        } else if ((node.getParent().toString().compareTo("Databases") == 0)
                && (node.getLevel() == 2)) {
            setIcon(databaseIcon);
        } else if ((node.toString().compareTo("Tables") == 0)
                && (node.getLevel() == 3)) {
            setIcon(tablesIcon);
        } else if ((node.getParent().toString().compareTo("Tables") == 0)
                && (node.getLevel() == 4)) {
            setIcon(tableIcon);
        }
        return this;
    }
}
